const app = getApp()
const $api = require('../../../utils/api.js').API;
Page({
    data: {
        list:{},
        str:'',
        num:''
    },
    onLoad: function(e) {
        this.setData({
            str:e.str,
            num:e.num
        })
        this.getList();
    },
    getList:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('address/list',data).then(res => {
            //请求成功
            if(res.data.code == 1){
              that.setData({
                list:res.data.data
              })
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    del:function(e){
        var id = e.target.dataset.id
        var that = this
        var data ={'id':id}
        $api.delete('address/delete',data).then(res => {
            //请求成功
            if(res.data.code == 1){
              that.getList();
              wx.showToast({
                title:'删除成功',
                duration:3000,//显示时长
                mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
                icon:'none', //图标，支持"success"、"loading" 
              })
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    addAddress:function(){
        wx.navigateTo({
            url:'/pages/user/address/add?str='+this.data.str+'&num='+this.data.num
        })
    },
    checktype:function(e){
        var that = this
        var data = {'uid':wx.getStorageSync('uid'),'id':e.target.dataset.id}
        $api.post('address/check',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'设置成功',
                    duration:3000,//显示时长
                    mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
                    icon:'none', //图标，支持"success"、"loading" 
                  })
                that.getList();
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
      }
});